//============================================================================
// Copyright (C) 2003-2013 Brett R. Jones 
// All Rights Reserved
//
// You may redistribute and/or modify for non commercial and commercial uses 
// provided this copyright notice remains in place and is not modified
//
// This code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// brettjones1900@gmail.com
// http://www.p2panarchy.com
//============================================================================

#include <string.h>
#include <VxUtilLib/VxMathDef.h>
#include "RcSysPktSearch.h"

//============================================================================
//=== constructor ===//
RcSysPktSearchReq::RcSysPktSearchReq()
    : m_u8SearchType(0)
    , m_u8Res1(0)
    , m_u16SearchFlags(0)
    , m_u32Res3(0)
{
    m_as8SearchExpression[0] = 0;
    m_u16PktType = RC_SYS_PKT_TYPE_SEARCH_REQ;
}

//============================================================================
void RcSysPktSearchReq::calcPktLen( void )
{
    m_u16PktLen = ROUND_TO_16BYTE_BOUNDRY( sizeof( RcSysPktSearchReq ) - RC_SYS_PKT_MAX_SEARCH_STR_LEN + strlen(m_as8SearchExpression) );
}
void			RcSysPktSearchReq::setSearchType( EScanType eScanType )		{ m_u8SearchType = (U8)eScanType; }
EScanType		RcSysPktSearchReq::getSearchType( void )						{ return (EScanType)m_u8SearchType; }
void			RcSysPktSearchReq::setSearchFlags( U16 u16SeachFlags )			{ m_u16SearchFlags = u16SeachFlags; }
U16				RcSysPktSearchReq::getSearchFlags( void )						{ return m_u16SearchFlags; }
bool			RcSysPktSearchReq::setSearchExpression( const char * pExp )	
{
	m_as8SearchExpression[0] = 0;
	if( pExp )
	{
		int len = strlen( pExp );
		if( len < sizeof( m_as8SearchExpression ) )
		{
			strcpy( m_as8SearchExpression, pExp );
			return true;
		}
	}
	return false;
}

//============================================================================
const char *	RcSysPktSearchReq::getSearchExpression( void )
{ 
	return m_as8SearchExpression; 
}

//============================================================================
//=== constructor ===//
RcSysPktSearchReply::RcSysPktSearchReply()
    : m_u8SearchType(0)
    , m_u16SearchFlags(0)
    , m_u16IdentMatchCount(0)
    , m_u16TotalIdentCount(0)
    , m_u32Res3(0)
{
    m_u16PktType = RC_SYS_PKT_TYPE_SEARCH_REPLY;
    calcPktLen();
}

//============================================================================
void RcSysPktSearchReply::calcPktLen( void )
{
    m_u16PktLen = ROUND_TO_16BYTE_BOUNDRY( sizeof( RcSysPktSearchReply ) - sizeof(m_aoSearchMatch) + m_u16TotalIdentCount * sizeof( VxNetIdent ) );
}

void			RcSysPktSearchReply::setSearchType( EScanType eScanType )		{ m_u8SearchType = (U8)eScanType; }
EScanType		RcSysPktSearchReply::getSearchType( void )						{ return (EScanType)m_u8SearchType; }
void			RcSysPktSearchReply::setSearchFlags( U16 u16SeachFlags )		{ m_u16SearchFlags = u16SeachFlags; }
U16				RcSysPktSearchReply::getSearchFlags( void )						{ return m_u16SearchFlags; }



